package com.anon.aop;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

/**
 * @author 徒有琴
 */
@Aspect
@Component
public class MyAspect {
    //    方法名默认就是切点的id
    @Pointcut("execution(* com.anon.service.impl.UserService2.sayHello())")
    public void point() {
    }

    @Before("point()")
    public void before(JoinPoint p) {
        System.out.println(p.getTarget());
        System.out.println(p.getArgs());
        System.out.println(p.getSignature().getName());
    }

    @AfterReturning(value="point()",returning="ret") // 后置通知
    public void myAfterReturning(JoinPoint a,Object ret){
        System.out.println("after~~~~:"+ret);
    }
}
